﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ChatForum.Database
{
    public static class DataRecordExtension
    {
        public static int GetInt32(this IDataRecord record, string fieldName)
        {
            return record.GetInt32(record.GetOrdinal(fieldName));
        }
        public static int? GetNullableInt32(this IDataRecord record, string fieldName)
        {
            int ordinal = record.GetOrdinal(fieldName);
            return record.IsDBNull(ordinal) ? null : (int?)record.GetInt32(ordinal);
        }
        public static string GetString(this IDataRecord record, string fieldName)
        {
            return record.GetString(record.GetOrdinal(fieldName));
        }
        public static DateTime GetDateTime(this IDataRecord record, string fieldName)
        {
            return record.GetDateTime(record.GetOrdinal(fieldName));
        }
        public static DateTime? GetNullableDateTime(this IDataRecord record, string fieldName)
        {
            int ordinal = record.GetOrdinal(fieldName);
            return record.IsDBNull(ordinal) ? null : (DateTime?)record.GetDateTime(ordinal);
        }
    }
}
